package project

import (
	"context"
	dto "git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/dto/business_opportunity"
	project "git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/repository/business_opportunity"
	pb "git.mycaigou.com/gfyx/micro-gfyx-mp-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/business_opportunity"
	"strings"
)

type projectService struct {
	projectRepo project.ProjectRepositoryIface
}

// NewProjectService
// 找项目
func NewProjectService(projectRepo project.ProjectRepositoryIface) ProjectServiceIface {
	return &projectService{
		projectRepo: projectRepo,
	}
}

// SearchProject 找项目
func (s *projectService) SearchProject(ctx context.Context, request *dto.SearchProjectRequest) (*dto.SearchProjectResponse, error) {
	data, err := s.projectRepo.SearchProject(ctx, &pb.SearchProjectRequest{
		Page:                   request.Page,
		PageSize:               request.PageSize,
		Keyword:                request.Keyword,
		OrganizingCode:         request.OrganizingCode,
		AreaCode:               request.AreaCode,
		CompanyAreaCode:        request.CompanyAreaCode,
		LandUsage:              request.LandUsage,
		ProjectType:            request.ProjectType,
		FitmentFee:             request.FitmentFee,
		CompanyType:            request.CompanyType,
		CompanyLabel:           request.CompanyLabel,
		IndustryCategory:       request.IndustryCategory,
		ProjectPriceGtAvgLabel: request.ProjectPriceGtAvgLabel,
		TakeLandDateStart:      request.TakeLandDateStart,
		TakeLandDateEnd:        request.TakeLandDateEnd,
		ProjectDateStart:       request.ProjectDateStart,
		ProjectDateEnd:         request.ProjectDateEnd,
		BuildingDateStart:      request.BuildingDateStart,
		BuildingDateEnd:        request.BuildingDateEnd,
		OpenDateStart:          request.OpenDateStart,
		OpenDateEnd:            request.OpenDateEnd,
		CompletedDateStart:     request.CompletedDateStart,
		CompletedDateEnd:       request.CompletedDateEnd,
	})
	resp := &dto.SearchProjectResponse{
		MaxNum: 5000,
		List:   make([]*dto.SearchProjectItem, 0),
	}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Total = data.Total
		for _, v := range data.List {
			row := s.dealProjectDetail(ctx, v)
			resp.List = append(resp.List, row)
		}
	}
	return resp, nil
}

func (s *projectService) dealProjectDetail(ctx context.Context, v *pb.ProjectData) *dto.SearchProjectItem {
	row := &dto.SearchProjectItem{
		Id:                       v.Id,
		ProjectStageLatest:       v.ProjectStageLatest,
		DeveloperName:            v.DeveloperName,
		OrganizingCode:           v.OrganizingCode,
		TopCompanyName:           v.TopCompanyName,
		TopCompanyOrganizingCode: v.TopCompanyOrganizingCode,
		CompanyType:              v.CompanyType,
		CompanyProvince:          v.CompanyProvince,
		CompanyProvinceCode:      v.CompanyProvinceCode,
		CompanyCity:              v.CompanyCity,
		CompanyCityCode:          v.CompanyCityCode,
		Province:                 v.Province,
		ProvinceCode:             v.ProvinceCode,
		City:                     v.City,
		CityCode:                 v.CityCode,
		Title:                    v.Title,
		PriceGtAvgLabel:          v.PriceGtAvgLabel,
		ProjectPriceGtAvgLabel:   v.ProjectPriceGtAvgLabel,
		Address:                  v.Address,
		IndustryCategoryBig:      v.IndustryCategoryBig,
		IndustryCategoryMiddle:   v.IndustryCategoryMiddle,
		IndustryCategorySmall:    v.IndustryCategorySmall,
		OrderDate:                v.OrderDate,
		ContactCnt:               v.ContactCnt,
		TitleHL:                  v.Title_HL,
		DeveloperNameHL:          v.DeveloperName_HL,
		LandTitleHL:              v.LandTitle_HL,
		BuildTitleHL:             v.BuildTitle_HL,
		OpeningTitleHL:           v.OpeningTitle_HL,
		Score:                    v.XScore,
		OpptyStatus:              v.OpptyStatus,
		LandInfoCnt:              v.LandInfoCnt,
		OpeningInfoCnt:           v.OpeningInfoCnt,
		BiddingInfoCnt:           v.BiddingInfoCnt,
		ProjectInfoCnt:           v.ProjectBaseInfoCnt,
	}
	if v.CompanyLabelArr != "" {
		row.CompanyLabelArr = strings.Split(v.CompanyLabelArr, ",")
	} else {
		row.CompanyLabelArr = make([]string, 0)
	}

	if v.LandUsageLabelArr != "" {
		row.LandUsageLabelArr = strings.Split(v.LandUsageLabelArr, ",")
	} else {
		row.LandUsageLabelArr = make([]string, 0)
	}

	if v.ProjectTypeLabelArr != "" {
		row.ProjectTypeLabelArr = strings.Split(v.ProjectTypeLabelArr, ",")
	} else {
		row.ProjectTypeLabelArr = make([]string, 0)
	}

	if v.FitmentFeeLabelArr != "" {
		row.FitmentFeeLabelArr = strings.Split(v.FitmentFeeLabelArr, ",")
	} else {
		row.FitmentFeeLabelArr = make([]string, 0)
	}

	//招标
	if v.BiddingInfoArr != nil {
		for _, v := range v.BiddingInfoArr {
			row.BiddingInfoArr = append(row.BiddingInfoArr, &dto.BiddingInfo{
				Id:          v.Id,
				Type:        v.Type,
				Title:       v.Title,
				PublishDate: v.PublishDate,
			})
		}
	} else {
		row.BiddingInfoArr = make([]*dto.BiddingInfo, 0)
	}

	//轨道图
	for _, v := range v.NodeList {
		nodeData := &dto.NodeData{
			NodeName: v.NodeName,
			NodeCnt:  v.NodeCnt,
			NodeDate: v.NodeDate,
			Status:   v.Status,
		}
		if v.DataList != nil {
			for _, p := range v.DataList {
				nodeData.DataList = append(nodeData.DataList, &dto.NodeDataTime{
					Time: p.Time,
				})
			}
		} else {
			nodeData.DataList = make([]*dto.NodeDataTime, 0)
		}
		row.NodeList = append(row.NodeList, nodeData)
	}
	return row
}

// FuzzySearchProject 模糊搜索项目
func (s *projectService) FuzzySearchProject(ctx context.Context, request *dto.FuzzySearchProjectRequest) ([]*dto.FuzzySearchProjectData, error) {
	data, err := s.projectRepo.FuzzySearchProject(ctx, &pb.FuzzySearchProjectRequest{
		Keyword: request.Keyword,
	})
	res := make([]*dto.FuzzySearchProjectData, 0)
	if err != nil {
		return res, err
	}
	if data != nil {
		for _, v := range data.List {
			res = append(res, &dto.FuzzySearchProjectData{
				TitleHL: v.TitleHL,
				Title:   v.Title,
			})
		}
	}
	return res, nil
}

// ProjectDetail 项目详情
func (s *projectService) ProjectDetail(ctx context.Context, request *dto.ProjectDetailRequest) (*dto.SearchProjectItem, error) {
	data, err := s.projectRepo.ProjectDetail(ctx, &pb.ProjectDetailRequest{
		Id: request.Id,
	})
	if err != nil {
		return &dto.SearchProjectItem{}, err
	}
	resp := &dto.SearchProjectItem{}
	if data != nil {
		resp = s.dealProjectDetail(ctx, data.Data)
	}
	return resp, nil
}

// ProjectDetailLand 项目详情 - 拿地列表
func (s *projectService) ProjectDetailLand(ctx context.Context, request *dto.ProjectDetailLandRequest) (*dto.ProjectDetailLandResponse, error) {
	data, err := s.projectRepo.ProjectDetailLand(ctx, &pb.ProjectDetailLandRequest{
		Page:      request.Page,
		PageSize:  request.PageSize,
		ProjectId: request.ProjectId,
	})
	resp := &dto.ProjectDetailLandResponse{
		List: make([]*dto.ProjectDetailLandItem, 0),
	}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Total = data.Total
		for _, v := range data.List {
			row := &dto.ProjectDetailLandItem{
				Id:              v.Id,
				DeveloperName:   v.DeveloperName,
				OrganizingCode:  v.OrganizingCode,
				Province:        v.Province,
				ProvinceCode:    v.ProvinceCode,
				City:            v.City,
				CityCode:        v.CityCode,
				InfoType:        v.InfoType,
				LandAddress:     v.LandAddress,
				LandTitle:       v.LandTitle,
				TakeLandDate:    v.TakeLandDate,
				LandUnitPrice:   v.LandUnitPrice,
				TakeLandPrice:   v.TakeLandPrice,
				AllArea:         v.AllArea,
				PriceGtAvgLabel: v.PriceGtAvgLabel,
			}
			if v.LandUsage != "" {
				row.LandUsage = strings.Split(v.LandUsage, "、")
			} else {
				row.LandUsage = make([]string, 0)
			}
			resp.List = append(resp.List, row)
		}
	}
	return resp, nil
}

// ProjectDetailBuild 项目详情 - 在建列表
func (s *projectService) ProjectDetailBuild(ctx context.Context, request *dto.ProjectDetailBuildRequest) (*dto.ProjectDetailBuildResponse, error) {
	data, err := s.projectRepo.ProjectDetailBuild(ctx, &pb.ProjectDetailBuildRequest{
		Page:      request.Page,
		PageSize:  request.PageSize,
		ProjectId: request.ProjectId,
	})
	resp := &dto.ProjectDetailBuildResponse{
		List: make([]*dto.ProjectDetailBuildItem, 0),
	}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Total = data.Total
		for _, v := range data.List {
			row := &dto.ProjectDetailBuildItem{
				Id:              v.Id,
				DeveloperName:   v.DeveloperName,
				OrganizingCode:  v.OrganizingCode,
				Province:        v.Province,
				ProvinceCode:    v.ProvinceCode,
				City:            v.City,
				CityCode:        v.CityCode,
				AllArea:         v.AllArea,
				CompletedTime:   v.CompletedTime,
				StartTime:       v.StartTime,
				ConscorpName:    v.ConscorpName,
				Address:         v.Address,
				PrjName:         v.PrjName,
				PrjPropertyNum:  v.PrjPropertyNum,
				PrjTypeNum:      v.PrjTypeNum,
				ContractPrice:   v.ContractPrice,
				PriceGtAvgLabel: v.PriceGtAvgLabel,
			}
			resp.List = append(resp.List, row)
		}
	}
	return resp, nil
}

// ProjectDetailSale 项目详情 - 开盘列表
func (s *projectService) ProjectDetailSale(ctx context.Context, request *dto.ProjectDetailSaleRequest) (*dto.ProjectDetailSaleResponse, error) {
	data, err := s.projectRepo.ProjectDetailSale(ctx, &pb.ProjectDetailSaleRequest{
		Page:      request.Page,
		PageSize:  request.PageSize,
		ProjectId: request.ProjectId,
	})
	resp := &dto.ProjectDetailSaleResponse{
		List: make([]*dto.ProjectDetailSaleItem, 0),
	}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Total = data.Total
		for _, v := range data.List {
			row := &dto.ProjectDetailSaleItem{
				Id:                v.Id,
				DeveloperName:     v.DeveloperName,
				OrganizingCode:    v.OrganizingCode,
				Province:          v.Province,
				ProvinceCode:      v.ProvinceCode,
				City:              v.City,
				CityCode:          v.CityCode,
				Region:            v.Region,
				BuildArea:         v.BuildArea,
				OpeningTime:       v.OpeningTime,
				DeliveryTime:      v.DeliveryTime,
				FitmentFee:        v.FitmentFee,
				Address:           v.Address,
				ProjectTitle:      v.ProjectTitle,
				SellStatus:        v.SellStatus,
				PriceGtAvgLabel:   v.PriceGtAvgLabel,
				NewHouseDealMoney: v.NewHouseDealMoney,
				NewHouseDealNum:   v.NewHouseDealNum,
				NewHouseOnNum:     v.NewHouseOnNum,
				NewHouseSaleRate:  v.NewHouseSaleRate,
			}
			resp.List = append(resp.List, row)
		}
	}
	return resp, nil
}

// ProjectDetailBid 项目详情 - 招中标列表
func (s *projectService) ProjectDetailBid(ctx context.Context, request *dto.ProjectDetailBidRequest) (*dto.ProjectDetailBidResponse, error) {
	data, err := s.projectRepo.ProjectDetailBid(ctx, &pb.ProjectDetailBidRequest{
		Page:      request.Page,
		PageSize:  request.PageSize,
		ProjectId: request.ProjectId,
	})
	resp := &dto.ProjectDetailBidResponse{
		List: make([]*dto.ProjectDetailBidItem, 0),
	}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Total = data.Total
		for _, v := range data.List {
			row := &dto.ProjectDetailBidItem{
				Id:             v.Id,
				DeveloperName:  v.DeveloperName,
				OrganizingCode: v.OrganizingCode,
				Province:       v.Province,
				City:           v.City,
				Title:          v.Title,
				PublishTime:    v.PublishTime,
				Type:           v.Type,
				DataSource:     v.DataSource,
			}
			//处理中标单位，去重
			row.SupplierList = make([]*dto.WinbidSupplier, 0)
			supplierNameArr := make([]string, 0)
			if v.FirstWinbidSupplierName != "" {
				supplierNameArr = append(supplierNameArr, v.FirstWinbidSupplierName)
				row.SupplierList = append(row.SupplierList, &dto.WinbidSupplier{SupplierName: v.FirstWinbidSupplierName, SupplierOrganizingCode: v.FirstWinbidSupplierOrganizingCode})
			}

			if v.SecondWinbidSupplierName != "" {
				secondExist := 0
				for _, p := range supplierNameArr {
					if p == v.SecondWinbidSupplierName {
						secondExist++
					}
				}
				if secondExist <= 0 {
					supplierNameArr = append(supplierNameArr, v.SecondWinbidSupplierName)
					row.SupplierList = append(row.SupplierList, &dto.WinbidSupplier{SupplierName: v.SecondWinbidSupplierName, SupplierOrganizingCode: v.SecondWinbidSupplierOrganizingCode})
				}
			}

			if v.ThirdWinbidSupplierName != "" {
				thirdExist := 0
				for _, p := range supplierNameArr {
					if p == v.ThirdWinbidSupplierName {
						thirdExist++
					}
				}
				if thirdExist <= 0 {
					supplierNameArr = append(supplierNameArr, v.ThirdWinbidSupplierName)
					row.SupplierList = append(row.SupplierList, &dto.WinbidSupplier{SupplierName: v.ThirdWinbidSupplierName, SupplierOrganizingCode: v.ThirdWinbidSupplierOrganizingCode})
				}
			}

			resp.List = append(resp.List, row)
		}
	}
	return resp, nil
}

// TakenLandDetail 拿地详情
func (s *projectService) TakenLandDetail(ctx context.Context, request *dto.TakenLandDetailRequest) (*dto.TakenLandDetailResponse, error) {
	data, err := s.projectRepo.TakenLandDetail(ctx, &pb.TakenLandDetailRequest{
		Id: request.Id,
	})
	resp := &dto.TakenLandDetailResponse{}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Id = data.Id
		resp.AllArea = data.AllArea
		resp.Authority = data.Authority
		resp.BuildEndPlan = data.BuildEndPlan
		resp.BuildStartPlan = data.BuildStartPlan
		resp.Capablitity = data.Capablitity
		resp.City = data.City
		resp.CityCode = data.CityCode
		resp.DeliverDate = data.DeliverDate
		resp.DeveloperName = data.DeveloperName
		resp.EnterpriseNature = data.EnterpriseNature
		resp.Industry = data.Industry
		resp.InfoType = data.InfoType
		resp.IsPriceGtAvg = data.IsPriceGtAvg
		resp.IsTopCompanyContainDeveloper = data.IsTopCompanyContainDeveloper
		resp.IssueDate = data.IssueDate
		resp.LandAddress = data.LandAddress
		resp.LandLevel = data.LandLevel
		resp.LandSource = data.LandSource
		resp.LandTitle = data.LandTitle
		resp.LandUnitPrice = data.LandUnitPrice
		resp.LandUnitPriceAvg = data.LandUnitPriceAvg
		resp.LandUsage = data.LandUsage
		resp.Lat = data.Lat
		resp.Lng = data.Lng
		resp.OrganizingCode = data.OrganizingCode
		resp.PlannedArea = data.PlannedArea
		resp.ProjectName = data.ProjectName
		resp.Province = data.Province
		resp.ProvinceCode = data.ProvinceCode
		resp.Region = data.Region
		resp.SourceUpdateTime = data.SourceUpdateTime
		resp.TakeLandDate = data.TakeLandDate
		resp.TakeLandPrice = data.TakeLandPrice
		resp.TopCompanyType = data.TopCompanyType
		resp.TopDeveloperName = data.TopDeveloperName
		resp.TopOrganizingCode = data.TopOrganizingCode
		resp.TopParentCompanyType = data.TopParentCompanyType
		resp.TradeType = data.TradeType
		resp.UseTimeDescription = data.UseTimeDescription
		//关联公司
		resp.RelatedCompany = make([]dto.RelatedCompany, 0)
		if data.RelatedCompany != nil {
			for _, v := range data.RelatedCompany {
				resp.RelatedCompany = append(resp.RelatedCompany, dto.RelatedCompany{
					CompanyName:       v.CompanyName,
					OrganizingCode:    v.OrganizingCode,
					Role:              v.Role,
					Labels:            v.Labels,
					TopCompanyName:    v.TopCompanyName,
					TopOrganizingCode: v.TopOrganizingCode,
				})
			}
		}
	}
	return resp, nil
}

// SaleList 开盘列表
func (s *projectService) SaleList(ctx context.Context, request *dto.SaleListRequest) (*dto.SaleListResponse, error) {
	data, err := s.projectRepo.SaleList(ctx, &pb.SaleListRequest{
		Page:                  request.Page,
		PageSize:              request.PageSize,
		Keyword:               request.Keyword,
		Area:                  request.Area,
		CompanyArea:           request.CompanyArea,
		CompanyType:           request.CompanyType,
		CompanyLabel:          request.CompanyLabel,
		IsPriceGtAvg:          request.IsPriceGtAvg,
		FitmentFeeLabel:       request.FitmentFeeLabel,
		PropertyCategoryLabel: request.PropertyCategoryLabel,
		OpeningTimeStart:      request.OpeningTimeStart,
		OpeningTimeEnd:        request.OpeningTimeEnd,
		DeliveryTimeStart:     request.DeliveryTimeStart,
		DeliveryTimeEnd:       request.DeliveryTimeEnd,
		OrganizingCode:        request.OrganizingCode,
	})

	resp := &dto.SaleListResponse{
		MaxNum: 5000,
		List:   make([]*dto.SaleListItem, 0),
	}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Total = data.Total
		for _, item := range data.List {
			row := &dto.SaleListItem{}
			row.Id = item.Id
			row.Address = item.Address
			row.City = item.City
			row.CityCode = item.CityCode
			row.DeliveryTime = item.DeliveryTime
			row.DeveloperName = item.DeveloperName
			row.FitmentFeeLabel = item.FitmentFee
			row.IsPriceGtAvg = item.IsPriceGtAvg
			row.NewHouseDealNum = item.NewHouseDealNum
			row.NewHouseOnNum = item.NewHouseOnNum
			row.NewHouseDealMoney = item.NewHouseDealMoney
			row.NewHouseSaleRate = item.NewHouseSaleRate
			row.OpeningTime = item.OpeningTime
			row.OrganizingCode = item.OrganizingCode
			row.ProjectTitle = item.ProjectTitle
			row.Province = item.Province
			row.ProvinceCode = item.ProvinceCode
			row.DeveloperNameHL = item.DeveloperName_HL
			row.ProjectTitleHL = item.ProjectTitle_HL
			row.SellStatus = item.SellStatus

			resp.List = append(resp.List, row)
		}
	}
	return resp, nil
}

// SaleDetail 开盘详情
func (s *projectService) SaleDetail(ctx context.Context, request *dto.SaleDetailRequest) (*dto.SaleDetailResponse, error) {
	data, err := s.projectRepo.SaleDetail(ctx, &pb.SaleDetailRequest{
		Id: request.Id,
	})
	resp := &dto.SaleDetailResponse{}
	if err != nil {
		return resp, err
	}
	if data != nil {
		resp.Id = data.Id
		resp.Address = data.Address
		resp.ArchitecturalStyle = data.ArchitecturalStyle
		resp.BuildArea = data.BuildArea
		resp.BuildingNum = data.BuildingNum
		resp.Characteristic = data.Characteristic
		resp.City = data.City
		resp.CityCode = data.CityCode
		resp.CoveredArea = data.CoveredArea
		resp.DeliveryTime = data.DeliveryTime
		resp.DeveloperName = data.DeveloperName
		resp.EnterpriseNature = data.EnterpriseNature
		resp.FitmentFee = data.FitmentFee
		resp.Households = data.Households
		resp.IsPriceGtAvg = data.IsPriceGtAvg
		resp.IsTopCompanyContainDeveloper = data.IsTopCompanyContainDeveloper
		resp.LandDate = data.LandDate
		resp.Lat = data.Lat
		resp.Lng = data.Lng
		resp.Level = data.Level
		resp.MaxArea = data.MaxArea
		resp.MinArea = data.MinArea
		resp.NewHouseDealNum = data.NewHouseDealNum
		resp.NewHouseOnNum = data.NewHouseOnNum
		resp.NewHouseDealMoney = data.NewHouseDealMoney
		resp.NewHouseSaleRate = data.NewHouseSaleRate
		resp.OpeningTime = data.OpeningTime
		resp.OrganizingCode = data.OrganizingCode
		resp.PresellNum = data.PresellNum
		resp.Price = data.Price
		resp.PriceCityAvg = data.PriceCityAvg
		resp.ProjectTitle = data.ProjectTitle
		resp.PropertyCategory = data.PropertyCategory
		resp.PropertyCompany = data.PropertyCompany
		resp.Province = data.Province
		resp.ProvinceCode = data.ProvinceCode
		resp.Region = data.Region
		resp.SellStatus = data.SellStatus
		resp.TopCompanyType = data.TopCompanyType
		resp.TopDeveloperName = data.TopDeveloperName
		resp.TopOrganizingCode = data.TopOrganizingCode
		resp.TopParentCompanyType = data.TopParentCompanyType
		resp.OpptyStatus = data.OpptyStatus
		resp.Decorate = data.Decorate
		//关联公司
		resp.RelatedCompany = make([]dto.RelatedCompany, 0)
		if data.RelatedCompany != nil {
			for _, v := range data.RelatedCompany {
				resp.RelatedCompany = append(resp.RelatedCompany, dto.RelatedCompany{
					CompanyName:    v.CompanyName,
					OrganizingCode: v.OrganizingCode,
					Role:           v.Role,
					Labels:         v.Labels,
				})
			}
		}
	}
	return resp, nil
}

// NewHouse 新房销售
func (s *projectService) NewHouse(ctx context.Context, request *dto.NewHouseRequest) (*dto.NewHouseResponse, error) {
	data, err := s.projectRepo.NewHouse(ctx, &pb.NewHouseRequest{
		Page:           request.Page,
		PageSize:       request.PageSize,
		OrganizingCode: request.OrganizingCode,
		PresellNum:     request.PresellNum,
	})
	resp := &dto.NewHouseResponse{
		List: make([]*dto.NewHouseItem, 0),
	}
	if err != nil {
		return resp, err
	}
	if request.OrganizingCode == "" || request.PresellNum == "" { //信用代码和预售证号任一为空，即返回空数据
		return resp, err
	}
	if data != nil {
		resp.Total = data.Total
		for _, v := range data.List {
			row := &dto.NewHouseItem{
				BuildArea:      v.BuildArea,
				BuildFloor:     v.BuildFloor,
				BuildName:      v.BuildName,
				CityName:       v.CityName,
				Developer:      v.Developer,
				InnerArea:      v.InnerArea,
				MasterId:       v.MasterId,
				OrganizingCode: v.OrganizingCode,
				PresellNum:     v.PresellNum,
				ProjectAddress: v.ProjectAddress,
				ProjectTitle:   v.ProjectTitle,
				RegionName:     v.RegionName,
				RoomName:       v.RoomName,
				RoomState:      v.RoomState,
				RoomUse:        v.RoomUse,
				SupplierDate:   v.SupplierDate,
				TradeDate:      v.TradeDate,
			}
			resp.List = append(resp.List, row)
		}
	}
	return resp, nil
}

// GetTopProject 获取项目主体
func (s *projectService) GetTopProject(ctx context.Context, request *dto.GetTopProjectRequest) (*dto.GetTopProjectResponse, error) {
	data, err := s.projectRepo.GetTopProject(ctx, &pb.GetTopProjectRequest{
		Id:       request.Id,
		PageSize: 1,
		Page:     1,
	})
	resp := &dto.GetTopProjectResponse{}
	if err != nil {
		return resp, err
	}
	if data != nil && data.Total > 0 {
		if data.List[0].NodeType != "" {
			resp.NodeType = data.List[0].NodeType + "阶段"
		}
		resp.TopProjectId = data.List[0].TopProjectId
		resp.PrjName = data.List[0].PrjName
	}
	return resp, nil
}
